package cn.com.qiancheng.service;

import cn.com.qiancheng.dao.AddStuDao;
import cn.com.qiancheng.dao.DeleteStuDao;
import cn.com.qiancheng.dao.StudentDao;
import cn.com.qiancheng.dao.TrinerClassDao;
import cn.com.qiancheng.dto.Student;
import cn.com.qiancheng.dto.TrinerClass;

public class UpdateStuService {
	public int validate(String userName,String realName,String password,String stuClass){
		int i = 0;
		StudentDao dao = new StudentDao();
		Student student = dao.searchStudentByUserName(userName);
		if(student==null){
			return i;
		}
		student.setStatus(1);
		if(realName!=null&&!realName.equals("")){
			student.setStuRealName(realName);
		}
		if(password!=null&&!password.equals("")){
			student.setStuPassword(MD5.GetMD5Code(password));
			student.setStatus(0);
		}
		if(stuClass!=null&&!stuClass.equals("")){
			TrinerClassDao tcd = new TrinerClassDao();
			TrinerClass tclass = tcd.sreachTrinerClass(stuClass);
			student.setStuClass(tclass.getId());
		}
		i = new AddStuDao().UpdateStudent(student);
		return i;
	}
	public int validate(String userName){
		int i = 0;
		DeleteStuDao delete = new DeleteStuDao();
		i = delete.deleteStudent(userName);
		return i;
	}
}
